#include"peter.h"

void chargementImage(perso *per)
{
	per->img_right[0]=load_bitmap("/home/rym/Bureau/jeux/1.bmp",NULL);
	per->img_right[1]=load_bitmap("/home/rym/Bureau/jeux/2.bmp",NULL);
	per->img_right[2]=load_bitmap("/home/rym/Bureau/jeux/3.bmp",NULL);
	per->img_right[3]=load_bitmap("/home/rym/Bureau/jeux/4.bmp",NULL);
	per->img_right[4]=load_bitmap("/home/rym/Bureau/jeux/5.bmp",NULL);
	per->img_right[5]=load_bitmap("/home/rym/Bureau/jeux/6.bmp",NULL);
	per->img_right[6]=load_bitmap("/home/rym/Bureau/jeux/7.bmp",NULL);
	per->img_right[7]=load_bitmap("/home/rym/Bureau/jeux/8.bmp",NULL);

	per->img_left[0]=load_bitmap("/home/rym/Bureau/jeux/11.bmp",NULL);
	per->img_left[1]=load_bitmap("/home/rym/Bureau/jeux/22.bmp",NULL);
	per->img_left[2]=load_bitmap("/home/rym/Bureau/jeux/33.bmp",NULL);
	per->img_left[3]=load_bitmap("/home/rym/Bureau/jeux/44.bmp",NULL);
	per->img_left[4]=load_bitmap("/home/rym/Bureau/jeux/55.bmp",NULL);
	per->img_left[5]=load_bitmap("/home/rym/Bureau/jeux/66.bmp",NULL);
	per->img_left[6]=load_bitmap("/home/rym/Bureau/jeux/77.bmp",NULL);
	per->img_left[7]=load_bitmap("/home/rym/Bureau/jeux/88.bmp",NULL);

}
 
 void gravity_per(perso *p,BITMAP * Background)
	{

	(p->y)+=4;
	p->direction = 2;

	
	
	}

void deplacement(perso *per,int *i,int *j, BITMAP *Buffer)
{ BITMAP *Image_i;
 int k;
//Image_i=per->img_right[0];
	if (key[KEY_LEFT] && (per->x)>-20)
	{
	if ((*i)==7) {(*i)=0;}
	per->x-=8;
	per->direction=0;
	//(*i)++;
	Image_i=per->img_left[(*i)+1];
	draw_sprite(Buffer, Image_i,per->x,per->y );
	usleep(50000);
	blit(Buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
	(*i)++;
	
	}
	if (key [KEY_RIGHT] && (per->x)<SCREEN_W)
	{
	if ((*j)==7) {(*j)=0;}
	per->x+=8;
	per->direction=1;
	Image_i=per->img_right[(*j)+1];
	draw_sprite(Buffer, Image_i,per->x,per->y );
	usleep(50000);
	blit(Buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
	(*j)++;
	}
	
	if (key [KEY_SPACE])
	{
	per->y-=25;
	draw_sprite(Buffer, Image_i,per->x,per->y );
	blit(Buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
	}

	if ((per->y) <= SCREEN_H-(per->img_right[0]->h))
	{
	gravity_per(per, Buffer);
	}
	
	}



